package com.wangtao.firstapp.utils;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.activity.EditorWishActivity;

/**
 * 自定义Dialog  “移动至心愿单”
 * Created by lanouhn on 16/9/12.
 */
public class DialogUtils {

    private Context context;
    private AlertDialog.Builder aBuilder;
    private AlertDialog alertDialog;

    public DialogUtils(Context context) {
        this.context = context;
    }

    public void dialog(String stringD, View.OnClickListener onClickListener) {
        aBuilder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.likes_wish_dialog, null);
        aBuilder.setView(view);
        aBuilder.setCancelable(false);
        alertDialog = aBuilder.create();

        ImageView bad = (ImageView) view.findViewById(R.id.bad_likes_wish_dialog);//右上角的“X”，点击退出Dialog
        //容器，放置“我的喜欢”。点击后退出Dialog,toast
        LinearLayout lltLike = (LinearLayout) view.findViewById(R.id.lltLike_likes_wish_dialog);
        Button cancel = (Button) view.findViewById(R.id.cancel_likes_wish_dialog);//点击后，取消喜欢，并退出Dialog
        TextView found = (TextView) view.findViewById(R.id.found_likes_wish_dialog);//点击后，跳转至 编辑心愿单页面
        ImageView shopPhoto = (ImageView) view.findViewById(R.id.shopPhoto_likes_wish_dialog);//商品图片，获取显示
        Picasso.with(context).load(stringD).into(shopPhoto);

        bad.setOnClickListener(onClickListener);
        cancel.setOnClickListener(onClickListener);
        lltLike.setOnClickListener(onClickListener);
        found.setOnClickListener(onClickListener);
        alertDialog.show();
    }

    //退出Dialog
    public void badIma() {
        alertDialog.cancel();
    }

    //退出Dialog，在Activity中写取消喜欢
    public void cancelBtn() {
        alertDialog.cancel();
    }

    //退出Dialog，并Toast
    public void lltLike() {
        alertDialog.cancel();
    }

    //跳转至，编辑心愿单页面
    public void found() {
        Intent intent = new Intent(context, EditorWishActivity.class);
        context.startActivity(intent);
    }

}
